import {Body, Controller, Delete, Get, Param, Post, Put, Query} from '@nestjs/common';
import {FileService} from "./file.service";
import {exec} from "child_process";
import {FileEntity} from "./file.entity";

@Controller('file')
export class FileController {

    constructor(
        private fileService: FileService
    ) {
    }

    @Get()
    async fetch(@Query() {path, isDirectory}) {
        return this.fileService.fetch(path, isDirectory)
    }

    @Get("search")
    async search(@Query() {path, search}) {
        return this.fileService.search(path, search);
    }

    @Post()
    async open(@Query() {path}) {
        await this.fileService.open(path)
    }

    @Put("move")
    async move(@Body() file: FileEntity, @Query("targetPath") targetPath: string) {
        await this.fileService.move(file, targetPath);
    }

    @Put("rename")
    async rename(@Body() file: FileEntity, @Query("newName") newName: string) {
        await this.fileService.rename(file, newName)
    }

    @Put("copy")
    async copy(@Body() file: FileEntity, @Query("targetPath") targetPath: string) {
        await this.fileService.copy(file, targetPath);
    }

    @Put("delete")
    async remove(@Body() file: FileEntity) {
        await this.fileService.remove(file);
    }

}
